/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package battleship.game;

import java.util.List;
import util.InputTaker;
import util.MsgPrinter;

/**
 *
 * @author ali
 */
public class StatePlayer1Turn extends AbstractState {

    private static AbstractState instance;

    public static AbstractState getInstance() {
        if (StatePlayer1Turn.instance == null) {
            StatePlayer1Turn.instance = new StatePlayer1Turn();
        }
        return StatePlayer1Turn.instance;
    }

    @Override
    public void execute() {

        String humanName = Game.getHumanPlayer().getName();
        MsgPrinter.print(humanName + "'s turn");
        String msg2User = humanName + ", please enter location to hit : ";
        List<Integer> xy = InputTaker.takeInput(msg2User);

        int x = xy.get(0);
        int y = xy.get(1);
        try {
            boolean wasHitPossible = Game.getCompPlayer().getBoard().hit(x, y);

        } catch (IllegalArgumentException e) {
            String playerName = Game.getHumanPlayer().getName();
            String hint = "Incorrect values entered. " + playerName + ", wasted turn";
            MsgPrinter.print(hint);
        }


    }

    @Override
    public StateType getNextState() {
        AbstractState statePlayer2Turn = StatePlayer2Turn.getInstance();

        AbstractState stateCheckWinner = StateCheckWinner.getInstance(statePlayer2Turn);
        return stateCheckWinner;
    }
}
